package com.mikufufu.blog.controller.api;

import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.common.entity.Query;
import com.mikufufu.blog.model.vo.api.SearchVO;
import com.mikufufu.blog.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/search")
@Api(tags = "搜索模块")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/list")
    @ApiOperation(value = "搜索（10条）", notes = "通过关键字搜索文章，并且返回最符合的前十条数据")
    @ApiImplicitParam(name = "content", value = "搜索内容（关键字）", required = true)
    public AjaxResult<List<SearchVO>> list(@NotNull(message = "搜索内容不能为空") String content) {
        return AjaxResult.data(searchService.list(content));
    }

    @GetMapping("/page")
    @ApiOperation(value = "更多搜索内容 分页", notes = "通过关键字搜索文章")
    @ApiImplicitParam(name = "content", value = "搜索内容（关键字）", required = true)
    public AjaxResult<List<SearchVO>> page(Query query, @NotNull(message = "搜索内容不能为空") String content) {
        return AjaxResult.data(searchService.page(query,content));
    }
}

